package com.htgd.gardenexpo.controller;


import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.dto.GeConTheaterMovieDTO;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConTheaterMovie;
import com.htgd.gardenexpo.page.MovieQuery;
import com.htgd.gardenexpo.service.GeConTheaterMovieService;
import com.htgd.gardenexpo.vo.GeConTheaterMovieVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 剧场资源 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-02
 */
@RestController
@RequestMapping("/api/movie")
@Api(tags = "剧场资源")
@Slf4j
public class GeConTheaterMovieController {

    @Autowired
    private GeConTheaterMovieService geConTheaterMovieService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConTheaterMovieDTO geConTheaterMovieDTO) {
        log.info("剧场电影-添加：{}",geConTheaterMovieDTO);
        return geConTheaterMovieService.add(geConTheaterMovieDTO);
    }

    @PostMapping(value = "/edit")
    @ApiOperation("编辑")
    public CommonResult edit(@RequestBody GeConTheaterMovieDTO geConTheaterMovieDTO) {
        log.info("剧场电影-编辑：{}",geConTheaterMovieDTO);
        return geConTheaterMovieService.edit(geConTheaterMovieDTO);
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation("删除")
    public CommonResult delete(String id) {
        GeConTheaterMovie geConTheaterMovie = new GeConTheaterMovie();
        geConTheaterMovie.setId(id);
        geConTheaterMovie.setIsDelete("1");
        geConTheaterMovieService.updateById(geConTheaterMovie);
        return CommonResult.success("删除成功");
    }

    @GetMapping(value = "/list")
    @ApiOperation("查询")
    public CommonResult<List<GeConTheaterMovieVO>> list(MovieQuery movieQuery) {
        log.info("剧场电影-列表查询：{}",movieQuery);
        PageInfo<GeConTheaterMovieVO> list = geConTheaterMovieService.pageList(movieQuery);
        return CommonResult.success(String.valueOf(list.getTotal()),list.getList());
    }

    @GetMapping(value = "/details")
    @ApiOperation("详情")
    public CommonResult<GeConTheaterMovieVO> details(String id) {
        GeConTheaterMovieVO geConTheaterMovieVO = new GeConTheaterMovieVO();
        GeConTheaterMovie byId = geConTheaterMovieService.getById(id);
        BeanUtils.copyProperties(byId,geConTheaterMovieVO);
        return CommonResult.success("查询成功",geConTheaterMovieVO);
    }

    @PostMapping(value = "/review")
    @ApiOperation("审核")
    public CommonResult review(@RequestBody GeConTheaterMovie geConTheaterMovie) {
        log.info("剧场资源-审核：{}",geConTheaterMovie);
        return geConTheaterMovieService.review(geConTheaterMovie);
    }

}
